package org.greenwire.provider;

import org.greenwire.dao.AccountBookDAO;
import org.greenwire.dao.impl.SqliteAccountBookDAO;
import org.greenwire.util.Constants;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;

public class AccountBookProvider extends ContentProvider {
	
	private AccountBookDAO accountBookDAO = new SqliteAccountBookDAO(getContext());
	
	private static UriMatcher uriMatcher;
	private static final int ACCOUNTS = 0;
	private static final int ACCOUNT = 1;
	private static final int ACCOUNTS_BY_DATE = 2;
	
	static{
		uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
		uriMatcher.addURI(Constants.AUTHORITY, "account", ACCOUNTS);
		uriMatcher.addURI(Constants.AUTHORITY, "account/#", ACCOUNT);
		uriMatcher.addURI(Constants.AUTHORITY, "accountsByDate/*", ACCOUNTS_BY_DATE);
	}
	
	@Override
	public int delete(Uri uri, String selection, String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getType(Uri uri) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Uri insert(Uri uri, ContentValues values) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean onCreate() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Cursor query(Uri uri, String[] projection, String selection,
			String[] selectionArgs, String sortOrder) {
		switch(uriMatcher.match(uri)){
		case ACCOUNTS_BY_DATE:
			String gmtHappened = uri.getPathSegments().get(1);
			return accountBookDAO.getCursorByDate(gmtHappened);
		}
		return null;
	}

	@Override
	public int update(Uri uri, ContentValues values, String selection,
			String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}

}
